package cn.bjsxt.plane;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

import cn.bjsxt.util.Constant;

public class Bullet extends GameObject {
	int speed = 3;
	double degree;
	
	public Bullet () {
		degree = Math.random()*Math.PI*2;
		x = Constant.GAME_WIDTH / 2;
		y = Constant.GAME_HEIGHT / 2;
		width = 5;
		height = 5;
	}
	
	public void draw(Graphics g) {
		Color c = g.getColor();
		g.setColor(Color.yellow);
		g.fillOval((int)x, (int)y, width, height);
		
		x += speed*Math.cos(degree);
		y += speed*Math.sin(degree);
		
		if (x < width || x > Constant.GAME_WIDTH - width) {
			degree = Math.PI-degree;
		}
		if (y < height || y > Constant.GAME_HEIGHT - height) {
			degree = - degree;
		}
		
		g.setColor(c);
	}
}
